package org.gvp.generator.core.writer.impl;

import org.gvp.generator.constant.ImportConstant;
import org.gvp.generator.core.WriterToResources;
import org.gvp.generator.core.writer.AbstractFileWriter;
import org.gvp.generator.props.CreateProps;
import org.gvp.generator.props.ProjectProps;
import org.gvp.generator.table.TableInfo;

import java.nio.file.Path;
import java.nio.file.Paths;

@WriterToResources
public class MapperXmlFileWriter extends AbstractFileWriter {
    @Override
    public void execute(TableInfo tableInfo, ProjectProps project) {
        String map = """
                <mapper namespace="%s.%s.%s.%sMapper">
                                
                </mapper>
                               
                """.formatted(project.getGroupId(),project.getModuleName(),project.getMapperPackage(),tableInfo.getUpperName());
        channel.writeNewline(ImportConstant.XML_HEADER);
        channel.writeNewline(map);
    }

    @Override
    public boolean isWriterFile(CreateProps create) {
        return create.isCreateMapperXml();
    }

    @Override
    public Path getFilePath(String basePath, ProjectProps project, String fileName) {
        return Paths.get(basePath,project.getXmlDirPath(),fileName + "Mapper.xml");
    }
}
